<?php

//1.判断是否为空

function doUploadAction(){
    //前端以数组的方式上传图片
    if(empty($_FILES['file']['name'])){
        echo '头像为空';
        echo '<br />';
        echo "<a href='index.php'>重新输入</a>";
        die;
    }else{
        move_uploaded_file($_FILES['file']['tmp_name'],'img/'.$_FILES['file']['name']);
        //    if(is_array($_FILES['file']['name'])){
        //        $count = count($_FILES['file']['name']);
        //        //echo '图片数量： '.$count;
        //        for($i=0;$i<$count;$i++){
        //            move_uploaded_file($_FILES['file']['tmp_name'][$i],'img/'.$_FILES['file']['name'][$i]);
        //        }
        //    }else{//非数组的方式上传图片
        //        move_uploaded_file($_FILES['file']['tmp_name'],'img/'.$_FILES['file']['name']);
        //    }
        $url = 'img/'.$_FILES['file']['name'];
        echo '头像：<img src='.$url.' width="100px" height="100px">';
        echo '<br />';
    }
}


//`头像：<img src='img/u=1595072465,3644073269&fm=193&f=GIF.jpg'>`
doUploadAction();
if(empty($_POST['userName'])){
    echo '姓名为空';
    echo '<br />';
    echo "<a href='index.php'>重新输入</a>";
    die;
}else{
    $name = $_POST['userName'];
}
if(empty($_POST['sex'])){
    echo '性别为空';
    echo '<br />';
    echo "<a href='index.php'>重新输入</a>";
    die;
}else{
    $sex = $_POST['sex'];
}
if(empty($_POST['hobby'])){
    echo '爱好为空';
    echo '<br />';
    echo "<a href='index.php'>重新输入</a>";
    die;
}else{
    $frm_tag = $_POST['hobby'];
    for($i=0;$i<count($frm_tag);$i++){
        if($i==0){
            $str_tag = $frm_tag[$i];
        }else {
            $str_tag = $str_tag . "," . $frm_tag[$i];
        }
    }
}
if(empty($_POST['city'])){
    echo '意向城市为空';
    echo '<br />';
    echo "<a href='index.php'>重新输入</a>";
    die;
}else{
    $city = $_POST['city'];
}
if(empty($_POST['self'])){
    echo '自我介绍为空';
    echo '<br />';
    echo "<a href='index.php'>重新输入</a>";
    die;
}else{
    $self = $_POST['self'];
}
echo ' 姓名：'.$name;
echo '<br />';
echo ' 性别：'.$sex;
echo '<br />';
echo ' 特长：'.$str_tag;
echo '<br />';
echo ' 意向城市：'.$city;
echo '<br />';
echo ' 自我介绍：'.$self;
echo '<br />';

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>

</head>
<body>
<!--<button type="button" onclick="toupdateimg()">更换头像</button>-->
<button type="button" onclick="toupdateinfo()">更新个人资料</button>
</body>
<script type="text/javascript">
    function toupdateimg(){
        location.href='http://www.zy008.com/img.php';
    }
    function toupdateinfo(){
        console.log('nb');
        location.href='http://www.zy008.com/index.php';
    }
</script>
</html>


